package com.androidx.p013lv.mine.fragment;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.TextView;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.androidx.p013lv.base.bean.DeductTypeBean;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.mine.C1207R;
import com.androidx.p013lv.mine.adapter.VipCenterVipAdapter;
import com.androidx.p013lv.mine.bean.VipCenterBean;
import com.androidx.p013lv.mine.databinding.VipCenterFragmentBinding;
import com.androidx.p013lv.mine.model.VipCenterModel;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/* renamed from: com.androidx.lv.mine.fragment.VipCardFragment */
public class VipCardFragment extends VipCenterFragment implements ItemClickListener {
    CountDownTimer newTimes;
    private VipCenterVipAdapter vipAdapter;
    private List<VipCenterBean.VipCardListBean> vipCardList;

    public static VipCardFragment newInstance(int i) {
        Bundle bundle = new Bundle();
        bundle.putInt("data", i);
        VipCardFragment vipCardFragment = new VipCardFragment();
        vipCardFragment.setArguments(bundle);
        return vipCardFragment;
    }

    @Override // com.androidx.p013lv.mine.fragment.VipCenterFragment, com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        super.initViews();
        this.vipCardList = new ArrayList();
        VipCenterVipAdapter vipCenterVipAdapter = new VipCenterVipAdapter();
        this.vipAdapter = vipCenterVipAdapter;
        vipCenterVipAdapter.setItemListener(this);
        ((VipCenterFragmentBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getContext(), 0, false));
        ((VipCenterFragmentBinding) this.binding).recycler.setAdapter(this.vipAdapter);
        ((VipCenterModel) new ViewModelProvider((ViewModelStoreOwner) Objects.requireNonNull(getActivity())).get(VipCenterModel.class)).dataVipCenter().observe((LifecycleOwner) Objects.requireNonNull(getActivity()), new Observer<BaseRes<VipCenterBean>>() {
            /* class com.androidx.p013lv.mine.fragment.VipCardFragment.C13371 */

            public void onChanged(BaseRes<VipCenterBean> baseRes) {
                if (baseRes.getCode() == 200) {
                    VipCardFragment.this.vipCardList = baseRes.getData().getVipCardList();
                    VipCardFragment.this.vipAdapter.setData(VipCardFragment.this.vipCardList);
                    if (VipCardFragment.this.vipCardList == null || VipCardFragment.this.vipCardList.size() <= 0) {
                        VipCardFragment.this.bean.setRechType(-1);
                        VipCardFragment.this.bean.setMoney(0);
                        return;
                    }
                    VipCardFragment.this.clickVipCard(0);
                    return;
                }
                ToastUtils.getInstance().showSigh(baseRes.getMsg());
            }
        });
        getDeductData();
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        clickVipCard(i);
    }

    public void getDeductData() {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().deductType(), new HttpCallback<BaseRes<DeductTypeBean>>("getDeductData") {
            /* class com.androidx.p013lv.mine.fragment.VipCardFragment.C13382 */

            public void onLvSuccess(BaseRes<DeductTypeBean> baseRes) {
                if (VipCardFragment.this.binding != null && baseRes.getCode() == 200 && baseRes.getData() != null) {
                    ((VipCenterFragmentBinding) VipCardFragment.this.binding).llNewTime.setVisibility(0);
                    VipCardFragment.this.setNewPeopleTime(baseRes.getData().getCountDown());
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void setNewPeopleTime(long j) {
        CountDownTimerC13393 r6 = new CountDownTimer(j, 1000) {
            /* class com.androidx.p013lv.mine.fragment.VipCardFragment.CountDownTimerC13393 */

            public void onTick(long j) {
                if (VipCardFragment.this.binding != null && ((VipCenterFragmentBinding) VipCardFragment.this.binding).tvNewTimeHh != null && ((VipCenterFragmentBinding) VipCardFragment.this.binding).tvNewTimeMm != null && ((VipCenterFragmentBinding) VipCardFragment.this.binding).tvNewTimeSs != null) {
                    long j2 = j / 1000;
                    long j3 = j2 / 3600;
                    long j4 = (j2 / 60) % 60;
                    long j5 = j2 % 60;
                    if (j3 < 10) {
                        TextView textView = ((VipCenterFragmentBinding) VipCardFragment.this.binding).tvNewTimeHh;
                        textView.setText("0" + j3);
                    } else {
                        TextView textView2 = ((VipCenterFragmentBinding) VipCardFragment.this.binding).tvNewTimeHh;
                        textView2.setText("" + j3);
                    }
                    if (j4 < 10) {
                        TextView textView3 = ((VipCenterFragmentBinding) VipCardFragment.this.binding).tvNewTimeMm;
                        textView3.setText("0" + j4);
                    } else {
                        TextView textView4 = ((VipCenterFragmentBinding) VipCardFragment.this.binding).tvNewTimeMm;
                        textView4.setText("" + j4);
                    }
                    if (j5 < 10) {
                        TextView textView5 = ((VipCenterFragmentBinding) VipCardFragment.this.binding).tvNewTimeSs;
                        textView5.setText("0" + j5);
                        return;
                    }
                    TextView textView6 = ((VipCenterFragmentBinding) VipCardFragment.this.binding).tvNewTimeSs;
                    textView6.setText("" + j5);
                }
            }

            public void onFinish() {
                if (VipCardFragment.this.binding != null) {
                    ((VipCenterFragmentBinding) VipCardFragment.this.binding).llNewTime.setVisibility(8);
                }
                if (VipCardFragment.this.newTimes != null) {
                    VipCardFragment.this.newTimes.cancel();
                    VipCardFragment.this.newTimes = null;
                }
            }
        };
        this.newTimes = r6;
        r6.start();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void clickVipCard(int i) {
        for (int i2 = 0; i2 < this.vipCardList.size(); i2++) {
            this.vipCardList.get(i2).setSelected(false);
        }
        this.vipCardList.get(i).setSelected(true);
        this.vipAdapter.setData(this.vipCardList);
        this.bean.setMoney(this.vipCardList.get(i).getDisPrice());
        this.bean.setPurType(2);
        this.bean.setVipCardId(this.vipCardList.get(i).getCardId());
        this.dialogMessage = this.vipCardList.get(i).getCardName();
        setVipType(this.vipCardList.get(i).getTypes());
        ((VipCenterFragmentBinding) this.binding).setVipShow(1);
        if (this.vipCardList.get(i).getDownloadNum() != 0) {
            ((VipCenterFragmentBinding) this.binding).includeVipLayout.llVipDownNum.setVisibility(0);
            TextView textView = ((VipCenterFragmentBinding) this.binding).includeVipLayout.tvVipDownNum;
            textView.setText(this.vipCardList.get(i).getDownloadNum() + "");
        } else {
            ((VipCenterFragmentBinding) this.binding).includeVipLayout.llVipDownNum.setVisibility(8);
        }
        int cardType = this.vipCardList.get(i).getCardType();
        if (cardType == 1) {
            ((VipCenterFragmentBinding) this.binding).includeVipLayout.ivVipAuthority.setImageResource(C1207R.C1209drawable.mine_vip_authority_permanent);
        } else if (cardType == 2) {
            ((VipCenterFragmentBinding) this.binding).includeVipLayout.ivVipAuthority.setImageResource(C1207R.C1209drawable.mine_vip_authority_year);
        } else if (cardType == 3) {
            ((VipCenterFragmentBinding) this.binding).includeVipLayout.ivVipAuthority.setImageResource(C1207R.C1209drawable.mine_vip_authority_quarter);
        } else if (cardType == 4) {
            ((VipCenterFragmentBinding) this.binding).includeVipLayout.ivVipAuthority.setImageResource(C1207R.C1209drawable.mine_vip_authority_month);
        } else if (cardType != 5) {
            ((VipCenterFragmentBinding) this.binding).includeVipLayout.ivVipAuthority.setImageResource(C1207R.C1209drawable.mine_vip_authority_default);
        } else {
            ((VipCenterFragmentBinding) this.binding).includeVipLayout.ivVipAuthority.setImageResource(C1207R.C1209drawable.mine_vip_authority_svip);
        }
    }
}
